package it.uniroma3.dia.ia.textcategorization.datasource.odpdump;

import it.uniroma3.dia.ia.textcategorization.datasource.DataSourceException;

import java.io.IOException;
import java.util.Set;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

final class LinksCollector {

	static Set<String> getLinks(String path) {
		Set<String> links = null;
		LinksCollectorHandler handler = new LinksCollectorHandler(path);

		try {
			XMLReader reader = XMLReaderFactory.createXMLReader();
			reader.setContentHandler(handler);
			reader.parse(ODPDumpLocations.CONTENT);
			links = handler.getLinks();
		} catch (SAXException exception) {
			throw new DataSourceException(
					"Exception while trying to parse the dump's content.",
					exception);
		} catch (IOException exception) {
			throw new DataSourceException(
					"Exception while trying to access the dump's content.",
					exception);
		}
		
		return links;
	}

}
